from django.db import models

# Create your models here.
# 商品分类
class ClassLevel1(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    img = models.CharField(max_length=300, verbose_name=u'图标')
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "商品一级分类"

class ClassLevel2(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    img = models.CharField(max_length=300, verbose_name=u'图标')

    ClassID = models.ForeignKey('ClassLevel1',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'一级分类')
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "商品二级分类"

class ClassLevel3(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    img = models.CharField(max_length=300, verbose_name=u'图标')

    ClassID = models.ForeignKey('ClassLevel2',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'二级分类')
    
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "商品三级分类"

# class ClassAttribute(models.Model):


    
# 商品信息
class GoodsBase(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'名称')
    price = models.FloatField(null=True, blank=True, verbose_name=u'价格')
    src = models.CharField(max_length=300, verbose_name=u'主图地址')
    star_time = models.DateTimeField(auto_now_add=True,verbose_name=u'创建日期')   
    last_time = models.DateTimeField(auto_now=True,verbose_name=u'最后一次修改日期')  
    isDelete = models.BooleanField(default=True,verbose_name=u'是否可用') 
    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = "商品基本信息"

#商品详细
class GoodesDetailed(models.Model):
    GENDER_CHOICES = (
        (u'1', u'上架'),
        (u'2', u'下架'),
    )
    title = models.CharField(max_length=300, verbose_name=u'描述')
    imgList = models.TextField(verbose_name=u'小图地址')
    richText =  models.TextField(verbose_name=u'图文介绍')
    star_time = models.DateTimeField(auto_now_add=True,verbose_name=u'创建日期')   
    last_time = models.DateTimeField(auto_now=True,verbose_name=u'最后一次修改日期')  
    shelves = models.CharField(
        max_length=30, verbose_name=u'上架状态', choices=GENDER_CHOICES)
    isDelete = models.BooleanField(default=True,verbose_name=u'是否可用')

    GoodsBase = models.OneToOneField(
        'GoodsBase', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'商品')

    goodsClass = models.ManyToManyField('ClassLevel3',verbose_name=u'分类') 
    Service = models.ForeignKey('GoodesService',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'服务列表')

    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = "商品详细信息"
#颜色
class color(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'名称')
    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = "商品颜色"

#规格
class specifications(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'名称')

    spe = models.ForeignKey('GoodsBase',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'服务列表')

    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = "商品规格"
#套餐
class package(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'名称')
    src = models.CharField(max_length=300, verbose_name=u'主图地址')
    colorID = models.OneToOneField(
        'color', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'颜色')
    GoodsID = models.OneToOneField(
        'GoodsBase', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'商品')
    speID = models.OneToOneField(
        'specifications', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'规格')
    price = models.FloatField(null=True, blank=True, verbose_name=u'价格')
    inventory = models.IntegerField(null=True, blank=True, verbose_name=u'库存')
    Goods = models.ForeignKey('GoodsBase',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'服务列表')



#商品总库存
class GoodsInventory(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'描述')
    GoodsBase = models.OneToOneField(
        'GoodsBase', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'商品')
    inventory = models.IntegerField(null=True, blank=True, verbose_name=u'总库存')
    star_time = models.DateTimeField(auto_now_add=True,verbose_name=u'创建日期')   
    last_time = models.DateTimeField(auto_now=True,verbose_name=u'最后一次修改日期')  
    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = "商品库存"

#服务类型
class GoodesService(models.Model):
    title = models.CharField(max_length=300, verbose_name=u'服务名称')
    msg = models.CharField(max_length=300,null=True, blank=True, verbose_name=u'备注')
    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "服务类型"

# class ServiceType(models.Model):
#     title = models.CharField(max_length=300, verbose_name=u'服务名称')
#     msg = models.CharField(max_length=300,null=True, blank=True, verbose_name=u'备注')
#     def __str__(self):
#         return self.title

#     class Meta:
#         verbose_name_plural = "服务类型"

#商品定位
class GoodsLocation1(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "一级定位"

class GoodsLocation2(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    ClassID = models.ForeignKey('GoodsLocation1',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'分类')
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "二级定位"

class GoodsLocation3(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'名称')
    msg = models.CharField(max_length=300, verbose_name=u'描述',null=True, blank=True)
    config = models.TextField(null=True, blank=True, verbose_name=u'自定义配置')
    ClassID = models.ForeignKey('GoodsLocation2',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'一级分类')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "三级定位"


#商品集合
class GoodsGather(models.Model):
    name = models.CharField(max_length=300, verbose_name=u'名称')
    GoodsBase = models.OneToOneField(
        'GoodsLocation3', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'商品位置')

    goodsList = models.ManyToManyField('GoodsBase',verbose_name=u'商品列表') 

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "商品集合"


#秒杀活动



